package io.xxx;

public class ReverseInteger {

    public static void main(String[] args) {
        System.out.println(reverse(123));
        System.out.println(reverse(-123));
        System.out.println(reverse(120));
        System.out.println(reverse(1056389759));
    }

    public static int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            int tmp = rev * 10 + x % 10;
            if (tmp / 10 != rev) {
                return 0;
            }
            rev = tmp;
            x /= 10;
        }
        return rev;
    }
}
